//
//  RecordCell.m
//  Zhiche-Carriage
//
//  Created by LeeBruce on 16/12/14.
//  Copyright © 2016年 LeeBruce. All rights reserved.
//

#import "RecordCell.h"

@implementation RecordCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self initSubviews];
    }
    
    return self;
}

-(void)initSubviews
{
    //时间
    self.timeLabel = [self backLabelWithFrame:CGRectMake(18, 0, 80 * kHeight, 33 * kHeight) andFont:12 andTextColor:carScrollColor andString:@"时间"];
    self.timeLabel.textAlignment = NSTextAlignmentCenter;
    
    //地址
    self.addressLabel = [self backLabelWithFrame:CGRectMake(CGRectGetMaxX(self.timeLabel.frame), 0, screenWidth - 80, 33 * kHeight) andFont:12 andTextColor:carScrollColor andString:@"地址"];
    self.addressLabel.textAlignment = NSTextAlignmentCenter;
    
    //图片
    UIImageView *imageV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"record"]];
    imageV.frame = CGRectMake(18, 78 * kHeight, 24, 25);
    [self.contentView addSubview:imageV];
    
    //价格
    self.priceLabel = [self backLabelWithFrame:CGRectMake(CGRectGetMaxX(imageV.frame), CGRectGetMidY(imageV.frame) - 20 * kHeight, 85, 40 * kHeight) andFont:12 andTextColor:YellowColor andString:@"价格"];
    self.priceLabel.textAlignment = NSTextAlignmentCenter;
    
    self.label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.priceLabel.frame) + 15, CGRectGetMidY(imageV.frame) - 40, 0.5, 80 * kHeight)];
    self.label.backgroundColor = LineGrayColor;
    [self.contentView addSubview:self.label];
    
    
}


-(void)showValue:(NSArray *)arr
{
    CGFloat h = 80 * kHeight/arr.count;
    
    for (int i = 0; i < arr.count; i++) {
        
        UILabel *leftLabel = [self backLabelWithFrame:CGRectMake(CGRectGetMaxX(self.label.frame) + 20, CGRectGetMinY(self.label.frame) + i*h , 80, h) andFont:12 andTextColor:carScrollColor andString:[NSString stringWithFormat:@"%@",arr[i][@"text"]]];
        leftLabel.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:leftLabel];

        UILabel *rightLabel = [self backLabelWithFrame:CGRectMake(CGRectGetMaxX(leftLabel.frame), CGRectGetMinY(self.label.frame) + i*h , 120, h) andFont:12 andTextColor:carScrollColor andString:[NSString stringWithFormat:@"%@",arr[i][@"priceText"]]];
        rightLabel.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:rightLabel];

        
    }
    
    
    
//    //运费
//    UILabel *freightLabel = [self backLabelWithFrame:CGRectMake(CGRectGetMaxX(label.frame) + 20, CGRectGetMinY(label.frame), 50, 20 * kHeight) andFont:12 andTextColor:carScrollColor andString:@"运费"];
//    
//    self.freightLabel = [self backLabelWithFrame:CGRectMake(CGRectGetMaxX(freightLabel.frame), CGRectGetMinY(freightLabel.frame), screenWidth - CGRectGetMaxX(freightLabel.frame) - 18, CGRectGetHeight(freightLabel.frame)) andFont:12 andTextColor:BlackTitleColor andString:@"1000"];
//    
//    //油费
//    UILabel *oilLabel = [self backLabelWithFrame:CGRectMake(CGRectGetMinX(freightLabel.frame) , CGRectGetMaxY(freightLabel.frame), CGRectGetWidth(freightLabel.frame),CGRectGetHeight(freightLabel.frame)) andFont:12 andTextColor:carScrollColor andString:@"油费"];
//    self.oilLabel = [self backLabelWithFrame:CGRectMake(CGRectGetMaxX(oilLabel.frame), CGRectGetMinY(oilLabel.frame), screenWidth - CGRectGetMaxX(oilLabel.frame) - 18, CGRectGetHeight(oilLabel.frame)) andFont:12 andTextColor:BlackTitleColor andString:@"1000"];
//    
//    
//    //油量
//    UILabel *amountLabel = [self backLabelWithFrame:CGRectMake(CGRectGetMinX(freightLabel.frame) , CGRectGetMaxY(oilLabel.frame), CGRectGetWidth(oilLabel.frame),CGRectGetHeight(oilLabel.frame)) andFont:12 andTextColor:carScrollColor andString:@"油量"];
//    self.amountLabel = [self backLabelWithFrame:CGRectMake(CGRectGetMaxX(oilLabel.frame), CGRectGetMinY(amountLabel.frame), screenWidth - CGRectGetMaxX(oilLabel.frame) - 18, CGRectGetHeight(oilLabel.frame)) andFont:12 andTextColor:BlackTitleColor andString:@"1000"];
//    
//    //油价
//    UILabel *oilpriceLabel = [self backLabelWithFrame:CGRectMake(CGRectGetMinX(freightLabel.frame) , CGRectGetMaxY(amountLabel.frame), CGRectGetWidth(freightLabel.frame),CGRectGetHeight(freightLabel.frame)) andFont:12 andTextColor:carScrollColor andString:@"油价"];
//    self.oilpriceLabel = [self backLabelWithFrame:CGRectMake(CGRectGetMaxX(oilLabel.frame), CGRectGetMinY(oilpriceLabel.frame), screenWidth - CGRectGetMaxX(oilLabel.frame) - 18, CGRectGetHeight(oilLabel.frame)) andFont:12 andTextColor:BlackTitleColor andString:@"1000"];
    
}

-(UILabel *)backLabelWithFrame:(CGRect)frame andFont:(int)a andTextColor:(UIColor *)color andString:(NSString *)string
{
    UILabel *label = [[UILabel alloc]init];
    label.frame = frame;
    label.textAlignment = NSTextAlignmentCenter;
    label.font = Font(a);
    [self.contentView addSubview:label];
    label.text = string;
    label.textColor = color;
    
    return  label;
}




- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
